package generic.net.observers;

import generic.net.Peer;
import generic.net.Request;
import java.util.Vector;

/**
 *
 * @author Adam Scarr <scarr.adam@gmail.com>
 */
public class RequestDispatcher {
    private Vector<RequestObserver> observers = new Vector<RequestObserver>();

    public synchronized void add(RequestObserver observer) {
        observers.add(observer);
    }

    public synchronized void remove(RequestObserver observer) {
        observers.remove(observer);
    }

    public synchronized void notifyRequestReceived(Peer peer, Request request) {
        for (RequestObserver observer: observers) {
            observer.requestReceived(peer, request);
        }
    }

    public synchronized int size() {
        return observers.size();
    }
}
